/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.asportoonline.tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import org.asportoonline.entities.Locale;

/**
 *
 * @author fe
 */
public class DettagliLocaleTag extends SimpleTagSupport {
    private Locale locale;

    /**
     * Get the value of locali
     *
     * @return the value of locali
     */
    public Locale getLocale() {
        return locale;
    }

    /**
     * Set the value of locali
     *
     * @param locali new value of locali
     */
    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    /**
     * Called by the container to invoke this tag. 
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */
    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        Locale l = getLocale();
        String[] chiusura = {"Nessuno", "Luned&igrave;", "Marted&igrave;", "Mercoled&igrave;", "Gioved&igrave;", "Venerd&igrave;", "Sabato", "Domenica"};
        
        try {
            
            if(l==null) {   //teoricamente non e' mai null
                out.print("<p>Nessun locale trovato!!</p>");
            }
            else {
                out.print("<div class=\"datiLocale\">"
                        + "<div class=\"dettagliLocale\">"
                        + "    <div class=\"logoL\">\n"
                        + "        <img src=\"img/" + l.getUrlimmagine() + "\" alt=\"immagine "+ l.getNome() + "\" />\n"
                        + "    </div>\n"
                        + "    <div class=\"listaDettagli\">\n"
                        + "        <ul>\n"
                        + "            <li><h6 id=\"nomeLocale\">" + l.getNome() + "</h6></li>\n"
                        + "            <li>" + l.getIndirizzo().getVia() + "</li>\n"
                        + "            <li>" + l.getIndirizzo().getCap() + " " + l.getIndirizzo().getCitta() + "</li>\n"
                        + "            <hr />\n"
                        + "            <li><b>Partita IVA</b> - " + l.getPiva() + "</li>\n"
                        + "            <li><b>Telefono</b> - " + l.getTelefono() + "</li>\n"
                        + "            <li><b>Email</b> - " + l.getEmail() + "</li>\n"
                        + "            <li><b>Distanza massima di consegna</b> - " + l.getDistanzaMassima() + "km</li>\n"
                        + "            <fieldset><legend><em>Orario</em></legend>"
                        + "                <li><b>Prima apertura</b> - " + l.getPrimaApertura() + "</li>\n");
                if(l.getSecondaApertura()!=null && !l.getSecondaApertura().isEmpty()) {
                out.print("                <li><b>Seconda apertura</b> - " + l.getSecondaApertura() + "</li>\n");
                }
                out.print("                <li></li>\n"
                        + "                <li><b>Giorno di chiusura</b> - " + chiusura[l.getGiornoChiusura()+1] + "</li>\n"
                        + "            </fieldset>"
                        + "        </ul>\n"
                        + "    </div>\n"
                        + "</div>\n"
                        + "<div id=\"map\">Your browser doesn't support Google Maps or Javascript is turned off.</div>\n"
                        + "<span type=\"hidden\" id=\"lat\" value=\""+l.getIndirizzo().getLatitudine()+"\"></span>"
                        + "<span type=\"hidden\" id=\"lon\" value=\""+l.getIndirizzo().getLongitudine()+"\"></span>"
                        + "</div>");                        
                out.flush();
            }
        } catch (java.io.IOException ex) {
            throw new JspException("Error in DettagliLocaleTag tag", ex);
        }
    }
}
